package com.yinda.dt.produce.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 2017/5/19 0019.
 */

public class ScrollListView extends LinearLayout {

    private Adapter adapter;

    public ScrollListView(Context context) {
        this(context, null);
    }

    public ScrollListView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ScrollListView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(LinearLayout.VERTICAL);
    }

    public void setAdapter(Adapter adapter) {
        this.adapter = adapter;
        notifyDataSetChanged();
    }

    public void notifyDataSetChanged(){
        removeAllViews();
        for (int i = 0; i < adapter.getItemCount(); i++) {
            addView(adapter.getItemView(this,i));
        }
    }

    public static abstract class Adapter {

        public abstract View getItemView(ViewGroup parent,int position);
        public abstract int getItemCount();
    }


}
